<template>
  <div>
    <el-dropdown @command="handleCommand" size="small">
      <el-button type="primary" size="mini">
        功能
        <i class="el-icon-arrow-down el-icon--right"></i>
      </el-button>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="info">详情</el-dropdown-item>
        <em v-if="level==1 || level==2">
          <el-dropdown-item
            command="edit"
            v-if="datarow.status===0||(datarow.status===1&&datarow.flowStatus===3)"
          >编辑</el-dropdown-item>
          <el-dropdown-item
            command="guanbi"
            v-if="datarow.status===0||(datarow.status === 1 && datarow.flowStatus===3)"
          >关闭</el-dropdown-item>
          <el-dropdown-item
            command="wancheng"
            v-if="datarow.status === 1 && datarow.flowStatus===2"
          >完成</el-dropdown-item>
        </em>
        <em v-else-if="level == 4">
          <em v-if="datarow.status==0">
            <el-dropdown-item command="judan">拒单</el-dropdown-item>
            <el-dropdown-item command="jiedan">接单</el-dropdown-item>
          </em>
          <em v-else-if="datarow.status==1&&datarow.flowStatus == 1 ">
            <el-dropdown-item command="judan">拒单</el-dropdown-item>
            <el-dropdown-item command="zuowanle">完成</el-dropdown-item>
          </em>
        </em>
      </el-dropdown-menu>
    </el-dropdown>
    <detail ref="detailId" :datarow="datarow" :cur_this="cur_this"></detail>
    <addwork ref="obj" :cur_this="cur_this" :is_add="false"></addwork>
    <zuowanle ref="zuo" :cur_this="cur_this"></zuowanle>
    <judan ref="ju" :cur_this="cur_this"></judan>
  </div>
</template>
<script>
import addwork from "./addwork";
import detail from "./detail";
import zuowanle from "./zuowanle";
import judan from "./judan";
import { _ordersModify } from "@/http/ajax";
export default {
  components: { detail, addwork, zuowanle, judan },
  props: {
    datarow: {
      type: Object,
      default: null
    },
    cur_this: {
      type: Object,
      default: null
    }
  },
  name: "dotag",
  data() {
    return {
      level: sessionStorage.level
    };
  },
  methods: {
    // 技术人员正常完成
    zuowanle() {
      const _this = this.$refs.zuo;
      _this.dialog = true;
      _this.datarow = this.datarow;
      _this.form.status = this.datarow.status;
      _this.form.flowStatus = this.datarow.flowStatus;
      _this.domInit({
        provinceId: this.datarow.provinceId,
        cityId: this.datarow.cityId,
        districtId: this.datarow.districtId
      });
    },
    // 技术人员拒单
    judan() {
      const _this = this.$refs.ju;
      _this.domInit(this.datarow.id);
    },
    handleCommand(v) {
      if (v === "info") {
        this.info();
      } else if (v === "guanbi") {
        this.modify(3, null);
      } else if (v === "jiedan") {
        this.modify(1, 1);
      } else if (v === "judan") {
        this.judan();
      } else if (v === "wancheng") {
        this.modify(2, 2);
      } else if (v === "zuowanle") {
        this.zuowanle();
      } else if (v === "edit") {
        this.edit();
      }
    },
    // 查看详情
    info() {
      const _this = this.$refs.detailId;
      _this.domInit(this.datarow.id);
    },
    modify(status, flowStatus) {
      let data = {
        id: this.datarow.id,
        flowStatus: flowStatus ? flowStatus : this.datarow.flowStatus,
        status: status ? status : this.datarow.status,
        images: this.datarow.images
      };
      _ordersModify(
        data,
        res => {
          this.$message({
            message: "操作成功",
            type: "success"
          });
          this.cur_this.getList();
        },
        err => {}
      );
    },
    edit() {
      const _this = this.$refs.obj;
      _this.dialog = true;
      _this.form = {
        customerName: this.datarow.customerName,
        categoryId: this.datarow.categoryId,
        phone: this.datarow.phone,
        actionUid: this.datarow.actionUid,
        address: this.datarow.address,
        mark: this.datarow.mark,
        provinceId: this.datarow.provinceId || 0,
        cityId: this.datarow.cityId||0,
        districtId: this.datarow.districtId||0,
        deptId: this.datarow.deptId,
        status: this.datarow.status,
        id: this.datarow.id,
      };
      _this.citys = {
        provinceId: this.datarow.provinceId||0,
        cityId: this.datarow.cityId||0,
        districtId: this.datarow.districtId||0
      };
      _this.domInit();
      _this.paidan();
    }
  }
};
</script>
<style lang="scss">
</style>
